package com.sbm.springsecurity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.sbm.domain.model.UserModel;
import com.sbm.svc.UserService;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

	@Autowired
	private UserService userService;

	@Override
	public UserDetails loadUserByUsername(String username) {
		System.out.println("————SpringSecurity登录认证————");
		System.out.println("用户：" + username);
		UserModel user = this.userService.login(username);
		if (user == null)
			throw new UsernameNotFoundException("用户名不存在");
		return new SecurityUser(user);
	}

}
